define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var ShellImpl = require('$UI/system/lib/portal/shellImpl');

	require("$UI/system/lib/cordova/cordova");
	require("cordova!cordova-plugin-statusbar");

	var Model = function() {
		this.callParent();
		// document.addEventListener("deviceready", function() {
		// window.StatusBar.hide();
		// });
		/*var shellImpl = new ShellImpl(this, {
			contentsXid : "pages",
			//wingXid : "wing",
			pageMappings : {
				"hello" : {
					url : "$$UI/highde/modbusItems/mainActivity.w"
				},
				"regist" : {
					url : "$$UI/highde/modbusItems/registActivity.w"
				},
				"welcome" : {
					url : "$$UI/highde/modbusItems/welcomeActivity.w"
				}
			}
		});*/
		/*var shellImpl = new ShellImpl(this, {

			"contentsXid" : "pages",
			"pageMappings" : {
				"hello" : {
					url : require.toUrl('./mainActivity.w')
				},
				"regist" : {
					url : require.toUrl('./registActivity.w')
				},
				"welcome" : {
					url : require.toUrl('./welcomeActivity.w')
				}
			}
		});*/
	};

	Model.prototype.modelLoad = function(event) {
		//justep.Shell.showPage("welcome");
		//debugger;
		this.comp("windowDialogLogin").open();
	};

	Model.prototype.windowDialogLoginReceived = function(event) {
		// justep.Shell.showPage("hello");
		// return;
		//justep.Shell.closeAll();
		//debugger;
		switch (event.data.mod) {
		case 'register':
			this.comp("windowDialogRegist").open();
			break;
		case 'forget':
			this.comp("windowDialogLogin").open();
			break;
		case 'login':
			if (event.data.flag)
				//if(this.comp("pages").getActiveIndex() == 0)
					this.comp("pages").slide('prev', 1);
				//justep.Shell.showPage("hello");
			else
				this.comp("windowDialogLogin").open();
			break;
		default:
			this.comp("windowDialogLogin").open();
			break; 
		}
	};

	Model.prototype.mainContainerBeforeLoad = function(event) {
		var name = localStorage.getItem("username");
		//debugger;
		if (name == null)
			this.comp("windowDialogLogin").open();
	};

	Model.prototype.mainContainerReceive = function(event) {
		debugger;
	};

	Model.prototype.windowDialogRegistReceived = function(event){
		this.comp("windowDialogLogin").open();
	};

	return Model;
});